package _18_剑指OfferII;

import java.util.LinkedList;
import java.util.Queue;

public class _041_剑指OfferII滑动窗口的平均值 {

    private int size;

    private Queue<Integer> queue;

    private double sum;

    /** Initialize your data structure here. */
    public _041_剑指OfferII滑动窗口的平均值(int size) {
        this.size = size;
        queue = new LinkedList<>();
    }

    public double next(int val) {
        if (queue.size() >= size) {
            sum -= queue.poll();
        }
        queue.offer(val);
        sum += val;
        return sum / queue.size();
    }

}
